<template>
  <el-table :data="list" border fit highlight-current-row style="width: 100%">
    <el-table-column
      v-loading="loading"
      align="center"
      label="活动ID"
      width="180"
      element-loading-text="请给我点时间！"
    >
      <template slot-scope="scope">
        <span>{{ scope.row.activityId }}</span>
      </template>
    </el-table-column>

    <el-table-column width="185px" align="center" label="活动名称">
      <template slot-scope="scope">
        <span>{{ scope.row.title}}</span>
      </template>
    </el-table-column>

    <el-table-column width="110px" align="center" label="活动渠道">
      <template slot-scope="scope">
        <span>{{ scope.row.channelCodes}}</span>
      </template>
    </el-table-column>

    <el-table-column width="360px" align="center" label="活动时间">
      <template slot-scope="scope">
        <span>{{ scope.row.startTime }} - {{ scope.row.endTime }}</span>
      </template>
    </el-table-column>

    <el-table-column width="110px" align="center" label="活动类型">
      <template slot-scope="scope">
        <span>{{ scope.row.frontPromotionType}}</span>
      </template>
    </el-table-column>

    <el-table-column class-name="status-col" align="center" label="状态" width="110">
      <template slot-scope="scope">
        <span>{{ scope.row.status }}</span>
      </template>
    </el-table-column>
    <el-table-column class-name="status-col" align="center" label="创建人" width="130">
      <template slot-scope="scope">
        <span>{{ scope.row.createUsername }}</span>
      </template>
    </el-table-column>
    <el-table-column class-name="status-col" align="center" label="创建时间" width="180">
      <template slot-scope="scope">
        <span>{{ scope.row.createTime }}</span>
      </template>
    </el-table-column>
    <el-table-column class-name="status-col" align="center" label="操作" width="290">
      <template slot-scope="scope">
        <span v-if="scope.row.type =='1'">
          <el-button type="text" class="textButton" @click="seeNewTab()">查看</el-button>
          <el-button type="text" class="textButton" @click="copyBtnShow()">复制</el-button>
          <el-button type="text" class="textButton" @click="closeActivity()">关闭</el-button>
          <el-button type="text" class="textButton" @click="appendMerchantProduct()">追加商品</el-button>
          <el-button type="text" class="textButton" @click="viewMarketingReport()">查看营销报告</el-button>
        </span>
        <span v-else-if="scope.row.type =='2' || scope.row.type =='3' ">
          <el-button type="text" class="textButton" @click="seeNewTab('filters')">查看</el-button>
          <el-button type="text" class="textButton" @click="copyBtnShow('filters')">复制</el-button>
          <el-button type="text" class="textButton" @click="viewMarketingReport('filters')">查看营销报告</el-button>
        </span>
        <span v-else-if="scope.row.type =='5'">
          <el-button type="text" class="textButton" @click="seeNewTab('filters')">查看</el-button>
          <el-button type="text" class="textButton" @click="copyBtnShow('filters')">复制</el-button>
          <el-button type="text" class="textButton" @click="updateBtnShow('filters')">编辑</el-button>
          <el-button type="text" class="textButton" @click="deleteActivity('filters')">删除</el-button>
        </span>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
// import { fetchList } from '@/api/article'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  props: {
    type: {
      type: String,
      default: '0'
    }
  },
  data() {
    return {
      list: [],
      tableList:{status0:[{"activityId":1910110000033005,"title":"满2件9折","promType":3,"frontPromotionType":"满X件Y折","startTime":"2019-10-11 00:00:00","endTime":"2019-10-16 10:06:22","status":"已过期","remark":null,"createUsername":"merchant","createUserid":1909160000172983,"createTime":"2019-10-11 10:08:19","isDeleted":0,"companyId":276,"createMerchantId":null,"createMerchantName":null,"activityType":1,"merchantType":1,"promPlatform":11,"payType":null,"canCreateActivity":1,"ruleDesc":null,"scopeType":null,"channelCodes":"BBC","hasWriteRoll":true,"type":2},{"activityId":1909280000084096,"title":"第2杯半价","promType":3,"frontPromotionType":"第X件Y元","startTime":"2019-09-28 17:36:33","endTime":"2019-10-01 17:36:35","status":"待提交","remark":null,"createUsername":"merchant","createUserid":1909160000172983,"createTime":"2019-09-28 17:37:19","isDeleted":0,"companyId":276,"createMerchantId":null,"createMerchantName":null,"activityType":1,"merchantType":1,"promPlatform":11,"payType":null,"canCreateActivity":1,"ruleDesc":null,"scopeType":null,"channelCodes":"BBC","hasWriteRoll":true,"type":5}],
        status1:[],
        status2:[{"activityId":1910110000033005,"title":"满2件9折","promType":3,"frontPromotionType":"满X件Y折","startTime":"2019-10-11 00:00:00","endTime":"2019-10-16 10:06:22","status":"已过期","remark":null,"createUsername":"merchant","createUserid":1909160000172983,"createTime":"2019-10-11 10:08:19","isDeleted":0,"companyId":276,"createMerchantId":null,"createMerchantName":null,"activityType":1,"merchantType":1,"promPlatform":11,"payType":null,"canCreateActivity":1,"ruleDesc":null,"scopeType":null,"channelCodes":"BBC","hasWriteRoll":true,"type":2}],
        status3:[],
        status5:[{"activityId":1909280000084096,"title":"第2杯半价","promType":3,"frontPromotionType":"第X件Y元","startTime":"2019-09-28 17:36:33","endTime":"2019-10-01 17:36:35","status":"待提交","remark":null,"createUsername":"merchant","createUserid":1909160000172983,"createTime":"2019-09-28 17:37:19","isDeleted":0,"companyId":276,"createMerchantId":null,"createMerchantName":null,"activityType":1,"merchantType":1,"promPlatform":11,"payType":null,"canCreateActivity":1,"ruleDesc":null,"scopeType":null,"channelCodes":"BBC","hasWriteRoll":true,"type":5}],
        },

      listQuery: {
        page: 1,
        limit: 5,
        type: this.type,
        sort: '+id'
      },
      loading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.$emit('create') // for test
      // fetchList(this.listQuery).then(response => {
        var key = 'status'+this.listQuery.type;
        this.list = this.tableList[key];
        this.loading = false
      // })
    },
    //查看 
    seeNewTab: function() {
      this.$router.push("/QueryPromotion2");
    },
    //复制
    copyBtnShow: function() {
      this.$confirm("是否确认复制该活动？", "提示", {
          type: "warning"
        })
        .then(() => {
          this.$message({message: "复制成功", type: "success"});
        })
        .catch(() => {
        });
      
    },
    //关闭
    closeActivity: function() {
      this.$confirm("是否确认关闭活动？", "提示", {
          type: "warning"
        })
        .then(() => {
          this.$message({message: "活动已关闭 ", type: "success"});
        })
        .catch(() => {
        });
      
    },
    deleteActivity: function() {
      this.$confirm("是否确认删除活动？", "提示", {
          type: "warning"
        })
        .then(() => {
          this.$message({message: "删除成功 ", type: "success"});
        })
        .catch(() => {
        });
      
    },
    updateBtnShow: function() {
      
      
    },
    //追加商品
    appendMerchantProduct: function() {
      
    },
    //查看营销报告
    viewMarketingReport: function() {
      this.$router.push("/MarketingReport");
    },
  }
}
</script>
<style scoped>
  .textButton {
    margin-left: 1px;
  }
</style>

